<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class DepartmentStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => 'required|unique:users|max:85',
            'description' => 'required|max:255',
            'parent_id' => 'required|integer',
        ];
    }

    public function messages(): array
    {
        return [
            'name.required' => '部门名称不能为空',
            'name.unique' => '部门名称已存在',
            'name.max' => '部门名称最大长度为85',
            'description.required' => '部门描述不能为空',
            'description.max' => '部门描述最大长度为255',
            'parent_id.required' => '父级部门不能为空',
            'parent_id.integer' => '父级部门格式不正确',
        ];
    }
}
